<?php

namespace App\Listeners;

use App\Events\Money\DepositEvent;
use App\Events\Money\Event;
use App\Events\Money\PrizeDepositEvent;
use App\Events\Money\ReversalEvent;
use App\Events\Money\TransferInEvent;
use App\Events\Money\TransferOutEvent;
use App\Events\Money\WithdrawEvent;
use App\Events\Money\ConsumeEvent;
use App\Models\UserMoneyLog;

class UserMoneySubscriber
{

    /**
     * 充值
     *
     * @param  object  $event
     * @return void
     */
    public function insertLog(Event $event)
    {
        $model = new UserMoneyLog();
        $model->user_id = $event->user_id;
        $model->money =  $event->money;
        $model->category = $event->category;
        $model->comment = $event->comment;
        $model->save();
    }


    /**
     * Register the listeners for the subscriber.
     * @param  \Illuminate\Events\Dispatcher  $events
     * @return array
     */
    public function subscribe($events)
    {
        return [
            DepositEvent::class => 'insertLog',
            WithdrawEvent::class => 'insertLog',
            ReversalEvent::class => 'insertLog',
            TransferInEvent::class => 'insertLog',
            TransferOutEvent::class => 'insertLog',
            PrizeDepositEvent::class => 'insertLog',
            ConsumeEvent::class => 'insertLog',
        ];
    }
}
